package redneuronal;

import java.text.*;

public class TestNeuralNetwork {
    public static void main(String args[]){
        // Entrada
        double xorInput[][] =
            {
                {0.0,0.0},
                {1.0,0.0},
                {0.0,1.0},
                {1.0,1.0}
            };
        // Matriz que debe aprender
        double xorIdeal[][] =
            { 
                {0.0},{1.0},
                {1.0},{0.0}
            };

        System.out.println("Aprendiendo:");
        /* Crea red 
        * 2 neuronas de entrada
        * 3 en la capa oculta
        * 1 en la capa de salida
        * Tasa de aprendizaje 0.7
        * Momento de entrenamiento 0.9
        */        
        Network network = new Network(2,3,1,0.7,0.9);

        NumberFormat percentFormat = NumberFormat.getPercentInstance();
        percentFormat.setMinimumFractionDigits(4);
        for (int i=0;i<10000;i++) {
            for (int j=0;j<xorInput.length;j++) {
                network.computeOutputs(xorInput[j]);
                network.calcError(xorIdeal[j]);
                network.learn();
            }
            System.out.println( "Intento #" + i + ",Error:" +
            percentFormat .format(network.getError(xorInput.length)) );
        }
        System.out.println("Resultado:");
        for (int i=0;i<xorInput.length;i++) {
            for (int j=0;j<xorInput[0].length;j++) {
                System.out.print( xorInput[i][j] +":" );
            }
            double out[] = network.computeOutputs(xorInput[i]);
            System.out.println("="+out[0]);
        }
    }
}